package com.tanhua;

import cn.hutool.core.util.RandomUtil;
import com.tanhua.sso.pojo.RecommendUser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Random;

@SpringBootTest
@RunWith(SpringRunner.class)
public class Demo {
    @Autowired
     private MongoTemplate mongoTemplate;

    @Test
    public void m1(){
        Criteria toUserId = Criteria.where("toUserId").is(1L);
        Query query = Query.query(toUserId).with(Sort.by(Sort.Order.desc("score"))).limit(1);
        RecommendUser recommendUser = mongoTemplate.findOne(query, RecommendUser.class);
        System.out.println(recommendUser);
    }

    @Test
    public void m3(){
        Random random=new Random();
        int i = random.nextInt(1);
        System.out.println(i);
    }
}
